
global datapath "~/DataFolder"
global Analyses "~/Results"


******************************************************* Table 8: Loan Dispersion


use "$datapath/RegData.dta", clear

global controls riskiness male avg_minority branch distance numsbl lretain size loan deposit p_ci p_re roa liquid

*Merge with contract Dispersion
merge 1:1 rssdhcr year fips using "$datapath/HMDA_Dispersion"
keep if _merge==3
drop _merge

gen log_std_riskiness = log(std_riskiness)

winsor2(logsdvolume log_std_riskiness), by(year) cuts(2.5 97.5) replace  

reghdfe logsdvolume spec_above5pctemp $controls ,absorb(county_year bank_state) cluster(fips)
outreg2 using Table8.xls, replace label dec(3) drop(num) nor2 stats(coef se) addstat(Adjusted R-squared,e(r2_a)) addtext(County*Year FE, Yes, Bank*State FE, Yes) 

reghdfe log_std_riskiness spec_above5pctemp $controls ,absorb(county_year bank_state) cluster(fips)
outreg2 using Table8.xls, append label dec(3) drop(num) nor2 stats(coef se) addstat(Adjusted R-squared,e(r2_a)) addtext(County*Year FE, Yes, Bank*State FE, Yes) 

gen str5 county_fips = string(fips,"%05.0f")
merge 1:1 rssdhcr county_fips year using "$datapath/LoanPerformance.dta"
drop if _merge ==2
drop _merge

gen log_std_itrate = log(std_itrate)
gen log_std_ltv = log(std_ltv)

winsor2 d60 d90 foreclosure credit ltv dti itrate avgloan_income avgmale avgminority log_std_itrate log_std_ltv , cut(2.5 97.5) by(year) replace

global controls2 credit ltv dti itrate avgloan_income avgmale avgminority branch distance numsbl lretain size loan deposit p_ci p_re roa liquid

reghdfe log_std_itrate spec_above5pctemp $controls2 , absorb(county_year bank_state) cluster(fips)
outreg2 using Table8.xls, append  label dec(3) drop(num) nor2 stats(coef se) addstat(Adjusted R-squared,e(r2_a)) addtext(County*Year FE, Yes, Bank*State FE, Yes) 

reghdfe log_std_ltv spec_above5pctemp $controls2 , absorb(county_year bank_state) cluster(fips)
outreg2 using Table8.xls, append label dec(3) drop(num) nor2 stats(coef se) addstat(Adjusted R-squared,e(r2_a)) addtext(County*Year FE, Yes, Bank*State FE, Yes) 





